package com.kun.oa.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.oa.entity.Permission;
import com.kun.oa.entity.Role;
import com.kun.oa.mapper.PermissionExample;
import com.kun.oa.mapper.RoleExample;
import com.kun.oa.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname RoleService
 * @Created by FangKun
 * @Date 2023/1/8 0008 下午 22:37
 */
@Service
public class RoleService {

    @Autowired
    private RoleMapper roleMapper;

    public PageInfo<Role> findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        RoleExample roleExample = new RoleExample();
        List<Role> list = roleMapper.selectByExample(roleExample);
        return new PageInfo<>(list);
    }

    public Role findById(int id) {
        // TODO Auto-generated method stub
        return roleMapper.findById(id);
    }

    public boolean addPermission(int id, int[] permissions) {
        return roleMapper.addPermissions(id,permissions)>0 ? true :false;
    }
}
